/**
 * 
 */
package com.jolestar.yayaweibotong.task;

import java.util.ArrayList;
import java.util.List;

import com.google.appengine.api.labs.taskqueue.TaskOptions;
import com.jolestar.yayaweibotong.dao.AccountDomain;
import com.jolestar.yayaweibotong.dao.UserDomain;
import com.jolestar.yayaweibotong.service.UserService;

/**
 * @author jolestar@gmail.com
 * 
 */
public class GetStatusQueueCronJob extends QueueCronJob {


	/**
	 * @param queueName
	 */
	public GetStatusQueueCronJob() {
		super(GetStatusTask.QUENE_NAME+"-job",GetStatusTask.QUENE_NAME);
	}

	@Override
	protected List<TaskOptions> buildTasks() {
		// TODO 多于100个用户
		List<UserDomain> users = UserService.ServiceHolder.getInstance()
				.getActivityUsers(0, 100);
		List<TaskOptions> tasks = new ArrayList<TaskOptions>(users.size());
		for (UserDomain user : users) {
			// String name = "put-status-task-"+user.getSafeEmail();
//			tasks.add(TaskOptions.Builder.param("email", user.getEmail()));
			switch(user.getSyncType()){
			case MasterSlave:
				AccountDomain account = user.getMasterAccount();
				if(account != null && account.isActivity()&&!account.isSuspend()){
					tasks.add(TaskOptions.Builder.param("account", account.getKeyName()));
				}
				break;
			case EachOther:
				List<AccountDomain> accounts = user.getAllAccounts();
				for(AccountDomain a:accounts){
					if(a.isActivity()&&!a.isSuspend()){
						tasks.add(TaskOptions.Builder.param("account", a.getKeyName()));
					}
				}
				break;
			}
		}
		return tasks;
	}

}
